<?php
class Visi_View_Helper_Linkify extends Zend_View_Helper_Abstract {

    /**
     * @todo Rewrite this to be more complex and configurable
     */
    public function linkify($text, $nofollow = true) {
    
        $nofollowattrib = "";
        if ($nofollow) {
            $nofollowattrib = ' rel="nofollow"';
        }
        $ret = ' ' . $text;
        $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<,]*)#ise", "'\\1<a href=\"\\2\"{$nofollowattrib}>\\2</a>'", $ret);
        $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<,]*)#ise", "'\\1<a href=\"http://\\2\"{$nofollowattrib}>\\2</a>'", $ret);
        $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
        $ret = substr($ret, 1);
        return $ret;
    
    }

}